Crate config [] [src]

Configuration is gathered by building a Source and then merging that source into the current state of the configuration.

// Add environment variables that begin with RUST_
config::merge(config::Environment::new("RUST")).unwrap();

// Add 'Settings.toml'
config::merge(config::File::new("Settings", config::FileFormat::Toml)
    .required(false)).unwrap();

// Add 'Settings.$(RUST_ENV).toml`
let name = format!("Settings.{}", config::get_str("env").unwrap_or("development".into()));
config::merge(config::File::new(&name, config::FileFormat::Toml)
    .required(false)).unwrap();

Note that in the above example the calls to config::merge could have been re-ordered to influence the priority as each successive merge is evaluated on top of the previous.

Configuration values can be retrieved with a call to config::get and then coerced into a type with as_*.

// Get 'debug' and coerce to a boolean
if let Some(value) = config::get("debug") {
    println!("{:?}", value.as_bool());
}

// You can use a type suffix
println!("{:?}", config::get_bool("debug"));
println!("{:?}", config::get_str("debug"));

See the examples for more usage information.

Structs

Config
Environment
File

Enums

FileFormat
Value

A configuration value.

Traits

Source
SourceBuilder

Functions

get
get_bool
get_float
get_int
get_map
get_slice
get_str
global
merge
set
set_default